/*
 * @Author: taoyuqing
 * @Date: 2022-12-22 19:56:51
 * @Description: 首页图片菜单按钮
 */
import 'package:flutter/material.dart';
import 'package:spree/utils/utils.dart';

// class ImageButton extends StatefulWidget {
//   final String url;
//   final String btName;
//   final Function? onTap;
//   ImageButton({Key? key, required this.url, required this.btName, this.onTap}) : super(key: key);

//   @override
//   State<ImageButton> createState() => _ImageButtonState();
// }

// class _ImageButtonState extends State<ImageButton> {
//   @override
//   Widget build(BuildContext context) {
//        double imgW = (Utils().getScreenWidth(context) - 110) / 6;
//     return GestureDetector(
//       onTap: (){
//         if (widget.onTap != null) {
//           widget.onTap!();
//         }
//       },
//       child: Container(
//         width: imgW,
//         child: Column(
//           crossAxisAlignment: CrossAxisAlignment.center,
//           children: [
//             Container(
//               width: imgW,
//               margin: EdgeInsets.only(bottom: 10),
//               child: Image.asset(
//                 widget.url,
//                 fit: BoxFit.fill,
//               ),
//             ),
//             Text(
//               widget.btName,
//               style: TextStyle(color: Color(0xFFB0AFEC), fontSize: 8),
//             )
//           ],
//         ),
//       ),
//     );
  
//   }
// }

class ImageButton extends StatelessWidget {
  final String url;
  final String btName;
  final Function? onTap;
  ImageButton({Key? key, required this.url, required this.btName, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    double imgW = (Utils().getScreenWidth(context) - 110) / 6;
    return GestureDetector(
      onTap: (){
        if (onTap != null) {
          onTap!();
        }
      },
      child: Container(
        width: imgW,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              width: imgW,
              margin: EdgeInsets.only(bottom: 10),
              child: Image.asset(
                url,
                fit: BoxFit.fill,
              ),
            ),
            Text(
              btName,
              style: TextStyle(color: Color(0xFFB0AFEC), fontSize: 8),
            )
          ],
        ),
      ),
    );
  }
}
